<?php
namespace Operation\Model;

use Zend\Db\Adapter\Adapter;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\AbstractTableGateway;

class StorecountTable extends AbstractTableGateway
{
    protected $table ='StoreCount';
    
    public function __construct(Adapter $adapter)
    {
        $this->adapter = $adapter;
        $this->resultSetPrototype = new ResultSet();
        $this->resultSetPrototype->setArrayObjectPrototype(new Salehead());
        $this->initialize();
    }
    
    public function getTbEcarts($where) {
        $sql = "SELECT 
                    SUM(difference) AS ec
                FROM ".$this->table."
                WHERE ".$where;
        //echo $sql.'<br />';
        $result = $this->adapter->query($sql)->execute();
        $return = $result->current();

        return $return;
    }
    
    public function getSynthEcarts($where, $groupby="") {
        $rows = array();
        $sql = "SELECT 
                    SUM(difference) AS ec,
                    date
                FROM ".$this->table."
                WHERE ".$where." ".$groupby;
        //echo $sql.'<br />';
        $result = $this->adapter->query($sql)->execute();
        for($x=0;$x<count($result);$x++):
            $rows[$x] = $result->current();
        endfor;
        
        return $rows;
    }
}
